package com.zk.shop.controller;

import com.zk.shop.service.ManagerService;
import com.zk.shop.util.FileUtil;
import com.zk.shop.util.FileUtilImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@RequestMapping("/api")
@Controller
public class HtmlController {

    @Autowired
    ManagerService managerService;
    @Autowired
    FileUtil fileUtil;

    @RequestMapping("/index/{mid}")
    public String jumpIndex(@PathVariable("mid") String mid) {
        if (!mid.matches("[0-9]+")) {
            return "403";
        }
        Integer loginStatus = managerService.getLoginStatusI(Integer.parseInt(mid));
        if (loginStatus > 0) {
            if(fileUtil.isContainName("index")){
                return "index";
            }else{
                return "403";
            }
        } else {
            return "403";
        }
    }

    @RequestMapping("/login")
    public String jumpLogin() {
        if(fileUtil.isContainName("login")){
            return "login";
        }else{
            return "403";
        }
    }

    @RequestMapping("/wel")
    public String jumpToWelcome() {
        if(fileUtil.isContainName("welcome")){
            return "welcome";
        }else{
            return "403";
        }
    }

    @RequestMapping("/manageraccount")
    public String jumpToMa() {
        if(fileUtil.isContainName("manageraccount")){
            return "manageraccount";
        }else{
            return "403";
        }
    }

    @RequestMapping("/orderlist")
    public String jumpToOrder() {
        if(fileUtil.isContainName("orderlist")){
            return "orderlist";
        }else{
            return "403";
        }
    }

    @RequestMapping("/shopaccount")
    public String jumpToSa() {
        if(fileUtil.isContainName("shopaccount")){
            return "shopaccount";
        }else{
            return "403";
        }
    }

    @RequestMapping("/shop")
    public String jumpToShop() {
        if(fileUtil.isContainName("shop")){
            return "shop";
        }else{
            return "403";
        }
    }

    @RequestMapping("/manager")
    public String jumpToManager() {
        if(fileUtil.isContainName("manager")){
            return "manager";
        }else{
            return "403";
        }
    }

    @RequestMapping("/menu")
    public String jumpToMenu() {
        if(fileUtil.isContainName("menu")){
            return "menu";
        }else{
            return "403";
        }
    }

    @RequestMapping("/role")
    public String jumpToRole() {
        if(fileUtil.isContainName("role")){
            return "role";
        }else{
            return "403";
        }
    }

    @RequestMapping("/rolemenu")
    public String jumpToRoleM() {
        if(fileUtil.isContainName("rolemenu")){
            return "rolemenu";
        }else{
            return "403";
        }
    }

    @RequestMapping("/rolemanager")
    public String rolemanager() {
        if(fileUtil.isContainName("rolemanager")){
            return "rolemanager";
        }else{
            return "403";
        }
    }
}
